//package fr.graffitiresearchlab;

class FontWriter
{
  GmlStrokeDrawer drawer;
  GmlBrushManager brushManager;
  float gmlScale;
  String s="";

  FontWriter()
  {
    // TEMP
    gmlScale = float(width)/10.0;
    drawer = new GmlLinesDrawer2D(2);
    brushManager = new GmlBrushManager();
    brushManager.setDefault(drawer);
  }

  void setString(String s)
  {
    this.s = s.toUpperCase();
  }

  // Quick & dirty
  // Needs to be rewritten
  void draw(Font f, float xCanvas, float yCanvas, float wCanvas)
  {
    if (f!=null)
    {
      float x=xCanvas;
      float y=yCanvas;
      float w=0,h=58;
      for (int i=0;i<s.length();i++)
      {
        char c = s.charAt(i);
        Letter letter = f.getLetter(c);
        boolean goAhead = false;
        if (c == ' ')
        {
          w = 58.0; // TEMP
          goAhead = true;
        }
        else
        if (letter !=null && letter.gml!=null)
        {
          AABB bb = letter.gml.getBoundingBox();
          w= bb.getExtent().x*gmlScale*2.0;
          h= bb.getExtent().y*gmlScale*2.0; // LAME
          goAhead = true;

          pushMatrix();
          translate(x,y);
          brushManager.draw(g, letter.gml, gmlScale);
          popMatrix();

        }

          if (goAhead)
          {
            x+=w;
            if (x>=wCanvas)
            {
              x = xCanvas;
              y+=h*1.1; // LAME
            }
          }
        
      }
    }
  }
}

